package com.bill.springcloud.hystrix.ribbon.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @fileName: HelloFeignService.java
 * @author: bin.li01
 * @date: 2018/2/1 10:47
 * @version: v1.0.0
 */
@Service
public class HelloRibbonService {

    @Resource
    private RestTemplate restTemplate;

    /**
     * 调用已经注册到服务（eureka-server）的eureka-client应用中的接口
     * @param name
     * @return
     */

    @HystrixCommand(fallbackMethod = "helloErr")
    public String helloFromEurekaClient(@RequestParam(value = "name") String name){
        return restTemplate.getForObject("http://EUREKA-CLIENT/hello?name=" + name,String.class);
    }

    public String helloErr(String name){
        return "ribbon sorry " + name;
    }
}
